﻿// -----------------------------------------------------------------------
// <copyright file="EmbeddedResourceFileSource.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Dhgms.TplHelper.Model.SqlCommandSource
{
    using System;
    using System.Collections.Generic;
    using System.Data.Common;
    using System.Linq;
    using System.Reflection;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public abstract class EmbeddedResourceFileSource<TDatabaseParameter> : SqlCommandSourceBase<TDatabaseParameter>
        where TDatabaseParameter : DbParameter
    {
        /// <summary>The resource namespace.</summary>
        private readonly string resourceNamespace;

        /// <summary>The resource file name.</summary>
        private readonly string resourceFileName;

        /// <summary>The assembly.</summary>
        private readonly Assembly assembly;

        /// <summary>Initializes a new instance of the <see cref="EmbeddedResourceFileSource{TDatabaseParameter}"/> class.</summary>
        /// <param name="assembly">The assembly.</param>
        /// <param name="resourceNamespace">The resource namespace.</param>
        /// <param name="resourceFileName">The resource file name.</param>
        protected EmbeddedResourceFileSource(Assembly assembly, string resourceNamespace, string resourceFileName)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            if (string.IsNullOrWhiteSpace(resourceNamespace))
            {
                throw new ArgumentNullException("resourceNamespace");
            }

            if (string.IsNullOrWhiteSpace(resourceFileName))
            {
                throw new ArgumentNullException("resourceFileName");
            }

            this.assembly = assembly;
            this.resourceNamespace = resourceNamespace;
            this.resourceFileName = resourceFileName;
        }

        /// <summary>
        /// Gets the command
        /// </summary>
        /// <returns>The string of the command to be executed.</returns>
        public sealed override string GetCommand()
        {
            return DataManager.Model.Helper.ReflectionExtensions.LoadStringFromResource(this.assembly, this.resourceNamespace, this.resourceFileName);
        }
    }
}
